<script lang="ts" setup>
import type { RoleStructure } from "@/api/role.ts"

const editData = ref({
  name: "",
  description: "",
  status: 1
})

const { data } = defineProps({
  data: {
    type: Object as PropType<RoleStructure>,
    default: () => {
      return {}
    }
  },
  type: {
    type: Number,
    required: true
  }
})

watchEffect(() => {
  if (data) {
    editData.value = { ...data }
  }
})

const emit = defineEmits(["submit"])
const handleSubmit = () => {
  emit("submit", editData.value)
}
</script>

<template>
  <el-form :model="editData" label-width="auto" style="max-width: 600px">
    <el-form-item label="角色名称">
      <el-input v-model="editData.name" placeholder="请输入名称"></el-input>
    </el-form-item>
    <el-form-item label="角色描述">
      <el-input
        v-model="editData.description"
        placeholder="请输入描述"
      ></el-input>
    </el-form-item>
    <el-form-item label="状态">
      <el-switch
        v-model="editData.status"
        :active-value="1"
        :inactive-value="0"
      >
      </el-switch>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="handleSubmit">保存</el-button>
    </el-form-item>
  </el-form>
</template>

<style scoped></style>
